package Ioperations;

import book.Book;
import book.Bookshelf;

import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 28318
 * Date: 2025-10-28
 * Time: 17:33
 */
public class AddIoperation implements Ioperations{
    @Override
    public void work(Bookshelf book) {
        System.out.println("***>添加图书...<***");
        if(book.bookshelf.length == book.getBookUsed()){
            System.out.println("书架剩余空间不足,无法添加...");
            return;
        }
        Scanner inPut = new Scanner(System.in);
        System.out.println("请输入要添加的图书名:");
        String name = inPut.nextLine();
        System.out.println("请输入图书的作者:");
        String author = inPut.nextLine();
        System.out.println("请输入图书的类型:");
        String type = inPut.nextLine();
        System.out.println("请输入图书的价格:");
        int price = inPut.nextInt();
        Book newBook = new Book(name,author,price,type);
        book.addBook(book.getBookUsed(),newBook);
        book.setBookUsed(book.getBookUsed() + 1);
        System.out.println("添加图书成功...");
    }
}
